<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ include file="/taglibs.jsp"%>
<%@page import="com.yaodian100.ec.campaign.entity.Campaign"%>

<%@page import="com.yaodian100.core.common.utils.ServerValue"%><s:url value="/js" var="jsPath"/>
<s:url value="/images" var="imgPath"/>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js" charset="UTF-8"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<!-- 時間 -->	
<script type="text/javascript" src="/js/jquery.timePicker.js"></script>
<link rel="stylesheet" type="text/css" href="/css/timePicker.css"/>	
<script type="text/javascript" charset="UTF-8" src="/js/jquery-ui-1.7.2.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/jquery-ui-1.7.2.custom.css"/>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>	
<script language="javascript"><!--
	$().ready( function() {
		$('#startDate').datepick({minDate: null, showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		$('#endDate').datepick({minDate:new Date(), showOn: 'both', 
	    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
		function customRange (){
			var startDt = $('#startDate').val(); //起始日
			var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
			return {minDate:endDt}; 
		}
		$("#productId").blur(function(){
			$("#productId").val(prodPadLeft($("#productId").val()));
		});
		//查询商品资料
		$("#findCampaignProduct").click(function(){
			$.post("<%=ServerValue.getMidContextPath()%>/campaignproduct/findCampaignProduct.do",{campProductId:$("#productId").val()},campProductCallback,"json");
		});
		//查询滿額購的商品资讯
		function campProductCallback(jsonCampMap){
			if ( jsonCampMap["error"] == "" ){//无任何error msg
				$("#showCampaignProductName").text(jsonCampMap["productName"]);
				$("#showCampaignCost").text(jsonCampMap["cost"]);
				$("#showCampaignPrice").text(jsonCampMap["price"]);
				$("#prod").text("ok");
			}else {
				$("#showCampaignProductName").html("<font color='red'><b>" + jsonCampMap["error"] + "</b></font>");
				$("#prod").text("");
			}
		}	

    $("#discount").blur(function(){
        if ( $("#prod").text() != "ok" ){
            alert("请先查询商品资料");
            return false;
        }
    });
		$("#startTime").timePicker();
		$("#endTime").timePicker();
		$("#discount").numeric({allow:"."});
		$("#minOrderAmount").numeric({allow:"."});
		$("#check_data").click(function(){
			if ( $("#productId").val() == "" ){
				alert("加购商品编号为必填");
				return false;
			}
			//if ( $("#discount").val() == "" || parseFloat($("#discount").val()) == 0 ){
			if ( $("#discount").val() == "" ){
				alert("商品金额为必填");
				return false;
			}
			
			//if ( $("#minOrderAmount").val() == "" || parseFloat($("#minOrderAmount").val()) == 0 ){
			if ( $("#minOrderAmount").val() == "" ){
				alert("最低订单金额为必填");
				return false;
			}			
			$("#formObj").submit();
		});
	 });
--></script>
<h1>满额购活动管理</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<s:form name="formObj" id="formObj" action="save.do" method="post">
<br />
<table class="tb-data" width="100%">
	<tr>
		<th>* 加购商品编号</th>
		<td>
			<c-rt:choose>
				<c-rt:when test="${empty campaign.uuid}">				
				<s:textfield name="campaign.productId" id="productId" size="8" maxlength="8"/>
				<input type="button" id="findCampaignProduct" value="查询商品" />
				<br/>
				<span id="showCampaignProductName"></span><span id="prod" style="display:none;"></span>
				</c-rt:when>
				<c-rt:otherwise>
					<s:textfield name="campaign.productId" id="productId" size="8" maxlength="8" disabled="true"/>
					<br/>
					<span id="showCampaignProductName">${product.productName}</span><span id="prod" style="display:none;">ok</span>
				</c-rt:otherwise>
			</c-rt:choose>
		</td>
	</tr>
	<tr>
		<th>目前商品成本/目前商品上架售价</th>
		<td>
			<c-rt:choose>
				<c-rt:when test="${empty campaign.uuid}">			
					￥<span id="showCampaignCost">0.0</span>/￥<span id="showCampaignPrice">0.0</span>
				</c-rt:when>
				<c-rt:otherwise>
					￥<span id="showCampaignCost"><fmt-rt:formatNumber value="${product.productCost}" pattern="#######0.0"/></span>/
					￥<span id="showCampaignPrice"><fmt-rt:formatNumber value="${shelf.shelfPrice}" pattern="#######0.0"/></span>
				</c-rt:otherwise>
			</c-rt:choose>
		</td>
	</tr>	
	<tr>
		<th>* 商品金额</th>
		<td>￥<s:textfield name="campaign.price" id="discount" size="10" maxlength="10"/>
		<span class="txt-rd">【※商品金额小数点1位数后无条件舍去】</span>
		</td>
	</tr>
	<tr>
		<th>* 活动起始日期时间</th>
		<td>
		<input name="startDate" id="startDate" size="10" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="yyyy-MM-dd"/>">
		<input name="startTime" id="startTime" size="8" value="<fmt:formatDate value="${campaign.startDateTime}" pattern="HH:mm"/>">
		</td>
	</tr>
	<tr>
		<th>* 活动结束日期时间</th>
		<td>
		<input name="endDate" id="endDate" size="10" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="yyyy-MM-dd"/>">
		<input name="endTime" id="endTime" size="8" value="<fmt:formatDate value="${campaign.endDateTime}" pattern="HH:mm"/>"></td>
	</tr>
	<tr>		
		<th>* 适用会员等级</th>
		<td><s:radio list="menuMemberRank.options" name="campaign.allowMemberRank" listKey="key" listValue="value.name"/></td>
	</tr>
	<tr>
		<th>* 最低订单金额</th>
		<td>￥<s:textfield name="campaign.minOrderAmount" id="minOrderAmount" size="20"/><span class="txt-rd">【※最低订单金额小数点1位数后无条件舍去】</span></td>
	</tr>
	<tr>
		<th>* 启用</th>
		<td>
			<input type="radio" name="campaign.enable" value="true" <c:if test="${campaign.enable}">checked</c:if>> 是　
			<input type="radio" name="campaign.enable" value="false" <c:if test="${!campaign.enable}">checked</c:if>> 否
	</tr>		
	<tr>
		<th>备注</th>
		<td><s:textarea name="campaign.memo" id="campaignMemo" rows="4" cols="60"/></td>
	</tr>
	<tr>
		<td colspan="2">
			<div class="f-link">
				<input type="button" id="check_data" value="储存修改">
<c:if test="${!empty campaign.uuid}">
				<input type="button" onclick="document.location='view.do'" value="回检视页">
</c:if><c:if test="${empty campaign.uuid}">
				<input type="button" onclick="document.location='search.do'" value="回活动查询页">
</c:if>
			</div>
		</td>
	</tr>		
</table>
</s:form>
